home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: gordon@sneaky.lerctr.org (Gordon Burditt)
- Newsgroups: comp.lang.c.moderated,comp.std.c
- Subject: Re: 'h' modifier in printf
- Date: 16 Mar 1996 10:21:26 -0600
- Organization: What organization?
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4iepq6$af6@solutions.solon.com>
- References: <4i801c$455@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
-
- >The "h" modifier says the corresponding argument will be printed as a
- >short or unsigned short.
- >
- >So, given:
- >
- >short s;
- >printf("%d", s);
- >printf("%hd", s);
-
- >Can these two ever be different?
-
- I don't think so, BUT:
- short s = -1;
- printf("%x\n", (unsigned int) s);
- printf("%hx\n", (unsigned int) s);
-
- /* is it allowed to leave out the casts? */
-
- prints, on a machine with 16-bit shorts and 32-bit ints:
-
- ffffffff
- ffff
-
- I believe this behavior in FreeBSD's gcc is correct, or at least allowed,
- behavior for the given machine architecture. The h modifier isn't
- totally useless, just mostly so.
-
- Gordon L. Burditt
- sneaky.lerctr.org!gordon
-